$("#addAdminBtn").on("click", function () {
    var userName = $(".userName").val();
    var userPassword = $(".userPassword").val();
    if (userName != null && userName.length != 0) {
        if (userPassword != null && userPassword.length != 0) {
            // 检查用户是否已注册
            $.ajax({
                type: "GET",
                url: "/userManage/checkUserName?userName=" + userName,
                dataType: "json",
                success: function (data) {
                    if (data.result == "success") {
                        $.ajax({
                            type: "POST",
                            url: "/adminManage/addAdmin",
                            data: $("#addAdminForm").serialize(),
                            dataType: "json",
                            success: function (data) {
                                if (data.result == "success") {
                                    alert("添加成功");
                                    window.location.reload();
                                } else {
                                    alert("添加失败");
                                }
                            },
                            error: function () {
                                alert("服务器错误，操作失败");
                            }
                        });
                    } else {
                        alert("该账户已注册");
                    }
                },
                error: function () {
                    alert("服务器错误，操作失败");
                }
            });
        } else {
            alert("密码不能为空");
        }
    } else {
        alert("用户名不能为空");
    }
});